package freemarker;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;

import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by yanfa on 2016/10/29.
 */
public class HavaTestFreeMarker {

    public static void main(String [] args) throws IOException, TemplateException {
        Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
        cfg.setDirectoryForTemplateLoading(
                new File("D:\\ZhanPeng\\Workspace\\J2ee\\SpringStudy\\spring-web-view\\src\\main\\webapp\\WEB-INF\\freemarker"));
        cfg.setDefaultEncoding("UTF-8");
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);

        Template freeMarkerTemplate = cfg.getTemplate("login_user.ftl");

        Map<String, Object> root = new HashMap<String, Object>();
        root.put("username", "ZhanPeng");
        root.put("password", "password");

        Writer out = new OutputStreamWriter(System.out);
        freeMarkerTemplate.process(root, out);

    }
}
